package com.citygis.basic;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName: test 
 * @Description: TODO
 * @author: liuzg
 * @Date: 2021/9/1 16:02
 * @Version: v1.0
 */
@SpringBootTest
public class test {

    public static void main(String[] args) {
        test.getTtimeDifference("2021-08-01 09:00:35","2021-08-01 09:00:12");
    }

    public static String a(String a, String b){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date now = null;
        java.util.Date date = null;
        try {
            now = df.parse(a);
            date =df.parse(b);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        long l=now.getTime()-date.getTime();
        long day=l/(24*60*60*1000);
        long hour=(l/(60*60*1000)-day*24);
        long min=((l/(60*1000))-day*24*60-hour*60);
        long s=(l/1000-day*24*60*60-hour*60*60-min*60);
        System.out.println(""+day+"天"+hour+"小时"+min+"分"+s+"秒");
        return "";
    }

    public static String getTtimeDifference(String one, String two) {
        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date begin = null;
        java.util.Date end = null;
        try {
            begin = dfs.parse(one);
            end = dfs.parse(two);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long between = (end.getTime() - begin.getTime()) / 1000;//除以1000是为了转换成秒

        long day1 = between / (24 * 3600);
        long hour1 = between % (24 * 3600) / 3600;
        long minute1 = between % 3600 / 60;
        long second1 = between % 60 / 60;
        String differ = day1 + "天" + hour1 + "小时" + minute1 + "分" + second1 + "秒";
        System.out.println(differ);
        return differ;
    }


}
